package com.hspedu.newData.dmsxl.数学技巧;
/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-28 
 * @Version: 1.0
 */

// todo 技巧
//  双指针交换
public class LC75颜色分类 {

    public void sortColors(int[] nums) {

        int[] res = new int[3];

        for (int i = 0; i < nums.length; i++) {
            res[nums[i]]++;
        }

        int i = res[0];
        for (int j = 0; j < i; j++) {
            nums[j] = 0;
        }
        for (int j = i; j < i + res[1]; j++) {
            nums[j] = 1;
        }
        for (int j = i+res[1]; j < i+res[1]+res[2]; j++) {
            nums[j] = 2;
        }
    }
}
